package top.wardyan.wbaseswt.util;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ShellUtil {
	
	public static Point getWindowSize() {
		//Rectangle rec = Display.getDefault().getClientArea();
		Rectangle rec = Display.getCurrent().getPrimaryMonitor().getClientArea();
		return new Point(rec.width, rec.height);
	}
	
	/**
	 * 将窗体设置为居中
	 * @param shell
	 */
	public static void center(Shell shell) {
		if(!shell.isDisposed()) {
			Point winsize = getWindowSize();
			shell.setLocation((winsize.x - shell.getSize().x) / 2, (winsize.y - shell.getSize().y) / 2);
		}
	}

}
